package com.atguigu.writable2;

import com.atguigu.wordcount.WCDriver;
import com.atguigu.wordcount.WCMapper;
import com.atguigu.wordcount.WCReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class FlowDriver {
    public static void main(String[] args) throws Exception {
        //1.创建Job实例
        Job job = Job.getInstance(new Configuration());

        //2.给Job赋值
        //设置Jar加载路径--将main方法所在的类传过去（如果是本地运行可以不写）
        //设置Mapper和Reducer类
        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReducer.class);
        //设置Mapper输出的key,value的类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);
        //设置最终输出的key,value的类型(在这是Reducer输出的key,value的类型)
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);
        //设置数据的输入输出路径
        FileInputFormat.setInputPaths(job,new Path("D:\\io\\input2"));
        //注意：输出的目录必须不存在
        FileOutputFormat.setOutputPath(job,new Path("D:\\io\\output3"));

        //3.运行Job
        /*
        waitForCompletion(boolean verbose)
        verbose : 是否打印用户执行时的信息
        返回值  ：如果为true表示执行成功
         */
        job.waitForCompletion(true);
    }
}
